package sample;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLOutput;

public class TestAction {
    public static void main(String[] args) {
        Frame frame = new Frame();
        Button button = new Button();
        /*监听事件*/
        //因为addActionListener()需要一个ActionListener,所以
        //我们需要构造一个ActionListener

        MyActionListener myActionListener = new MyActionListener();
        button.addActionListener(myActionListener);
        frame.add(button, BorderLayout.CENTER);//窗口增加按钮
        frame.pack();//窗口自适应
        frame.setVisible(true);//窗口可视化
        windowClose(frame);

    }
    private static void windowClose(Frame frame) {
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);//退出窗口
            }
        });
    }
}

class MyActionListener implements ActionListener {


    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("aaa");
    }
}